import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import './public.dart';

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with InitMixin, HttpErrorMixin {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: GlobalProvider.getProviders(),
        child: Consumer2<ThemeProvider, LocalProvider>(
            builder: (context, themeProvider, localProvider, child) {
          return ColorFiltered(
              colorFilter: ColorFilter.mode(
                Color.fromARGB(255, 255, 255, 255), // 主题滤镜
                BlendMode.darken,
              ),
              child: Stack(
                  alignment: Alignment.center,
                  fit: StackFit.expand,
                  children: [
                    buildGestureDetector(MaterialApp(
                      navigatorKey: ACGN.navGK,
                      title: '漫画先锋',
                      debugShowCheckedModeBanner: false,
                      theme: themeProvider.themeData(),
                      darkTheme:
                          themeProvider.themeData(platformDarkMode: true),
                      localizationsDelegates: [
                        I18n.delegate,
                        GlobalMaterialLocalizations.delegate,
                        GlobalWidgetsLocalizations.delegate,
                        GlobalCupertinoLocalizations.delegate
                      ],
                      localeListResolutionCallback: (List<Locale> locales,
                          Iterable<Locale> supportedLocales) {
                        return Locale('zh');
                      },
                      localeResolutionCallback:
                          (Locale locale, Iterable<Locale> supportedLocales) {
                        return Locale('zh');
                      },
                      supportedLocales: I18n.delegate.supportedLocales,
                      locale: localProvider.locale,
                      onGenerateRoute: ACGN.router.generator,
                      navigatorObservers: [ACGN.routeObserver],
                      home: SplashPage(),
                      builder: EasyLoading.init(),
                    )),
                    IgnorePointer(
                        child: Container(
                            decoration: BoxDecoration(
                                color: Color.fromARGB(
                                    themeProvider.lightNumber, 0, 0, 0))))
                  ]));
        }));
  }

  //隐藏键盘
  buildGestureDetector(Widget widget) {
    return GestureDetector(
        onTap: () {
          SystemChannels.textInput.invokeMethod('TextInput.hide');
        },
        child: widget);
  }
}
